// 添加日期格式化函数
function formatDate(date) {
  //   console.log("typeof date:", typeof date); //typeof date: object
  if (!date) return null;

  // 如果是 Date 对象，格式化为期望的字符串格式
  if (date instanceof Date) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, "0");
    const day = String(date.getDate()).padStart(2, "0");
    const hours = String(date.getHours()).padStart(2, "0");
    const minutes = String(date.getMinutes()).padStart(2, "0");
    const seconds = String(date.getSeconds()).padStart(2, "0");
    const milliseconds = date.getMilliseconds();

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
  }

  // 如果是字符串且为ISO格式，转换为期望的格式
  if (typeof date === "string" && date.includes("T")) {
    // 将 "2025-08-21T02:32:01.487Z" 转换为 "2025-08-21 02:32:01.487"
    return date.replace("T", " ").replace("Z", "");
  }

  // 其他情况直接返回原始值
  return date;
}

module.exports = {
  formatDate,
};
